##########################################################################
# Description: Replicates tables                                         #
# Author: Ozlem Tuncel                                                   #
# Title: Lecturer and Data Services Specialist                           #
# Affiliation: Georgia State University                                  #
# Department: Research Data Services & Political Science                 #
# Email: otuncelgurlek1@gsu.edu                                          #
# Date: 08/04/2025                                                       #
# R Version: R version 4.4.0 (2024-04-24 ucrt) -- "Puppy Cup"            #
# Computer: Dell Latitude 7450 x64-based PC                              #
# Processor: Intel(R) Core(TM) Ultra 7 165U, 2.10 GHz, 12 Cores          #
# BIOS version/date: Dell Inc. 1.3.0, 4/11/2024                          #
# OS: 22621.3880                                                         #
##########################################################################

# Clean slate
rm(list=ls())
set.seed(1234)
getwd()
# setwd() # use this to set the working directory

# Load library
library(tidyverse) # version 2.0.0
library(xtable)    # version 1.8-4

# Import data
my_data <- read_csv("replication_data/elite_interview_data.csv")
journal_data <- read_csv("replication_data/all_journals.csv")

# Table 1: Number of interviews in journals (2000-2023) ####
journal_data |> xtable(digits = c(0, 0, 0, 0, 0, 2))

# Table 2: Topics covered in elite interviews ####
my_data |> 
  group_by(topic) |> 
  summarise(count = n()) |> 
  mutate(perc = count/sum(count)*100,
         perc = round(perc, 1)) |> 
  arrange(-perc) |> 
  xtable()

# Table 3: Number of interviews conducted (n = 145) ####
my_data |> 
  mutate(cuts = cut(sample_size, c(0, 5, 15, 30, 50, 100, 200, Inf))) |> 
  group_by(cuts) |> 
  summarize(n = n()) |> 
  mutate(perc = n/sum(n)*100,
         perc = round(perc, 1)) |>
  rename(`Number of interviews conducted` = "cuts",
         `Count` = "n",
         `Percentage` = "perc") |> 
  xtable()
